(function() {

	Nokia.View = new Nokia.Class({
		initialize: function(options) {
			var instance = this;

			instance.options = jQuery.extend({ container: this._createContainter() }, options);

			instance.setContainer(instance.options.container);

			instance.init();
		},

		init: function() {
			// instance initializer
		},

		fireCallback: function(type) {
			var instance = this;
			var options = instance.options;

			if (jQuery.isFunction(options[type])) {
				var args = Array.prototype.slice.call(arguments, 1);

				options[type].apply(instance, args);
			}
		},

		renderUI: function() {
			// renderUI phase
		},

		bindUI: function() {
			// bindUI phase
		},

		syncUI: function() {
			// syncUI phase
		},

		setContainer: function(container) {
			this._container = jQuery(container).addClass('nokia-view-container');
		},


		getContainer: function() {
			return this._container;
		},

		setTemplate: function(template) {
			var instance = this;

			if (template instanceof Nokia.Template) {
				instance._template = template;
			}
		},

		getTemplate: function() {
			var instance = this;

			return instance._template;
		},

		render: function(target) {
			var instance = this;

			instance._renderUI(target || document.body);

	        instance.renderUI();
	        instance.bindUI();
	        instance.syncUI();

	        instance._rendered = true;
		},

		isRendered: function() {
			var instance = this;

			return instance._rendered;
		},

		show: function() {
			var instance = this;

			instance.getContainer().show();

			instance.fireCallback('show', arguments);
		},

		hide: function() {
			var instance = this;

			instance.getContainer().hide();

			instance.fireCallback('hide', arguments);
		},

		_createContainter: function() {
			return Nokia.dom.parseHTML('<div></div>');
		},

		_renderUI: function(target) {
			var instance = this;

			if (!instance._isLocated) {
				Nokia.dom.append(target, this.getContainer());

				instance._isLocated = true;
			}

		},

		destroy: function() {
			var instance = this;

			instance.getContainer().remove();
		}
	});

})();